import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { getMyOrder } from '../../api/Order/index';

const orderListStore = createSlice({
    name: 'orderListStore',
    initialState: {
        orderList: [],
        loading: false
    },
    reducers: {},
    extraReducers: (builder) => {
        builder
            .addCase(fetchOrderList.pending, (state) => {
                state.loading = true;
            })
            .addCase(fetchOrderList.fulfilled, (state, action) => {
                state.orderList = action.payload;
                state.loading = false;
                console.log('redux测试订单列表:', action.payload);
            })
            .addCase(fetchOrderList.rejected, (state) => {
                state.loading = false;
            });
    }
});
// 创建异步thunk
const fetchOrderList = createAsyncThunk('orderStore/fetchOrderList',
    async (params: { page: string; pageSize: string; orderState: number }) => {
        const res = await getMyOrder(params.page, params.pageSize, params.orderState);
        return res.result;
    }
);
export default orderListStore.reducer;
export { fetchOrderList };